/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 * Copyright 2009 Synergy Energy Holdings, LLC. All rights reserved.
 * 
 * ZipCode.java
 * @date: Feb 4, 2009
 * @author mlee
 */
package com.rhythm.commons.regx.patterns;

import com.rhythm.commons.regx.RegX;

/**
 *Matches standard 5 digit US Zip Codes, or the US ZIP + 4 Standard.
 * @author mlee
 */
public class Addresses {


    /**
     * Matches standard 5 digit US Zip Codes, or the US ZIP + 4 Standard.
     */
    private static final String US_ZIP_CODE_PATTERN = "^([0-9]{5}(([- //][0-9]{4})|([0-9]{4}))?)$";

    private Addresses(){
    }

    /**
     * Returns if the given {@code String} matches
     * standard 5 digit US Zip Codes, or the US ZIP + 4 Standard
     *</br><strong>examples<storng>
     * <pre>
     *  isUSZipCode("90210")                    = true
     *  isUSZipCode("90210-1234")           = true
     *  isUSZipCode("00000")                    = true
     *  isUSZipCode("12345-0000")           = true
     *  isUSZipCode("123450000")            = true
     *  isUSZipCode("12345A0000")           = false
     *  isUSZipCode("  12345")                  = false
     *  isUSZipCode("  12345  ")                = false
     *  isUSZipCode("12345  ")                  = false
     * </pre>
     *
     * @param str the source (nullable)
     * @return True is the given {@code String} matches
     * standard 5 digit US Zip Codes, or the US ZIP + 4 Standard, false otherwise
     *
     * @see RegX
     */
    public static synchronized boolean isUSZipCode(String str) {

        return ((str == null) ? false : RegX.contains(str, US_ZIP_CODE_PATTERN));
    }
}
